/*
 * @(#)LogServiceImpl.java
 *
 * Copyright 2011 Xinhua Online, Inc. All rights reserved.
 */

package com.winxuan.channel.service.commodity.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Service;

import com.winxuan.channel.model.commodity.CommodityLog;
import com.winxuan.channel.service.commodity.LogService;
import com.winxuan.support.dao.BaseDao;
import com.winxuan.support.dao.Finder;
import com.winxuan.support.dao.ParametersFinder;
import com.winxuan.util.pagination.Pagination;

/**
 * description
 * @author  HideHai
 * @version 1.0,2011-6-9
 */
@Service("logService")
public class LogServiceImpl implements LogService {

	@SuppressWarnings("unchecked")
	@Override
	public List<CommodityLog> getCommodityLogByDistribute(Integer distribute,Integer commodity,Pagination pagination) {
		final Map<String,Integer> params = new HashMap<String,Integer>();
		params.put("distribute", distribute);
		params.put("commodity", commodity);
		Finder finder = new ParametersFinder(params) {
			@Override
			public String genQueryString() {
				StringBuffer sb=new StringBuffer("SELECT cl FROM CommodityLog cl WHERE 1=1");
				if(params.get("distribute") != -1){
					sb.append(" AND cl.distribute=:distribute ");
				}
				if(params.get("commodity") != 0){
					sb.append(" AND cl.commodity=:commodity ORDER BY cl.executetime DESC");
				}
				return sb.toString();
			}
		};
		return baseDao.find(finder,pagination);
	}
	
	private BaseDao baseDao;

	public void setBaseDao(BaseDao baseDao) {
		this.baseDao = baseDao;
	}

}

